<?php
/**
 * Created by PhpStorm.
 * User: Kevin
 * Date: 2018/10/19
 * Time: 10:19
 */
namespace app\admin\model;
use think\Db;
use think\Model;
class NoticeModel extends Model
{
    protected $name = 'notice';

    public function getNoticeData($map,$Nowpage,$limits){
        $data = $this->where($map)
            ->field('n_id,n_title,n_content,n_type,n_app,n_user_id,n_read,n_delete,n_time,n_top')
            ->page($Nowpage,$limits)
            ->order('n_time desc')
            ->select();
        if(!empty($data)){
            foreach($data as $key=>$vo){
                if($vo['n_type'] == 1){
                    switch($vo['n_app']){
                        case 1:
                            $data[$key]['who'] = '全体用户';
                            break;
                        case 2:
                            $data[$key]['who'] = '全体商户';
                            break;
                        case 3:
                            $data[$key]['who'] = '全体业务员';
                            break;
                    }
                }elseif($vo['n_type'] == 2){
                    switch($vo['n_app']){
                        case 1:
                            $data[$key]['who'] = Db::name('u_user')->where('user_id',$vo['n_user_id'])->value('user_username');
                            break;
                        case 2:
                            $data[$key]['who'] = Db::name('shops')->where('s_id',$vo['n_user_id'])->value('s_name');
                            break;
                        case 3:
                            $data[$key]['who'] = Db::name('work_user')->where('user_id',$vo['n_user_id'])->value('user_name');
                            break;
                    }
                }
            }
        }
        return $data;
    }
}